
package com.example.tranhtheuchuthap;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;



import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class HieuChinh extends Activity{
	EditText edSoMau,edChieuCao,edChieuDai,edDoKho;
	Button btnGuiHieuChinh;
	TextView tvSoMau,tvChieuCao,tvChieuDai,tvDoKho;
	Bitmap photo=null;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hieuchinh);
		edSoMau=(EditText)findViewById(R.id.edtSoMau);
		edChieuCao=(EditText)findViewById(R.id.edtChieuCao);
		edChieuDai=(EditText)findViewById(R.id.edtChieuDai);
		edDoKho=(EditText)findViewById(R.id.edtDoKho);
		btnGuiHieuChinh=(Button)findViewById(R.id.guiHieuChinh);
		tvSoMau=(TextView)findViewById(R.id.tvSoMau);
		tvChieuCao=(TextView)findViewById(R.id.tvChieuCao);
		tvChieuDai=(TextView)findViewById(R.id.tvChieuDai);
		tvDoKho=(TextView)findViewById(R.id.tvDoKho);
		
		btnGuiHieuChinh.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(validateInput()){
				
					
					Intent i = new Intent();
					// Put Extras to the Intent
					i.putExtra("somau", edSoMau.getText().toString());
					i.putExtra("chieucao", edChieuCao.getText().toString());
					i.putExtra("chieudai", edChieuDai.getText().toString());
					i.putExtra("dokho", edDoKho.getText().toString());
					// Set the RESULT STATUS CODE and Intent
					setResult(RESULT_OK, i);
					finish();
				}
				
				
					
				
			}
		});
	}
public Boolean validateInput(){
	int somau,chieudai,chieucao,dokho;
		try{
	somau=Integer.parseInt(edSoMau.getText().toString());
	if(somau>100||somau<4) {
		tvSoMau.setText("Please input a number from 4 to 100");
		
	}
	
	else{
		tvSoMau.setText("");
	}
	}
	catch(Exception e){
		tvSoMau.setText("Please input a number from 4 to 100");
	}
		
		try{
			
			chieudai=Integer.parseInt(edChieuDai.getText().toString());
			if(chieudai>200||chieudai<20) {
				tvChieuDai.setText("Please input a number from 20 to 1024");
				
			}
			else{
				tvChieuDai.setText("");
			}
			}
			catch(Exception e){
				tvChieuDai.setText("Please input a number from 20 to 1024");
			}
		
		try{
			
			chieucao=Integer.parseInt(edChieuCao.getText().toString());
			if(chieucao>200||chieucao<20) {
				tvChieuCao.setText("Please input a number from 20 to 1024");
				
			}
			else{
				tvChieuCao.setText("");
			}
			}
			catch(Exception e){
				tvChieuCao.setText("Please input a number from 20 to 1024");
			}
		
		try{
			
			dokho=Integer.parseInt(edDoKho.getText().toString());
			if(dokho>3||dokho<1) {
				tvDoKho.setText("Please input a number from 1 to 3");
				
			}
			else{
				tvDoKho.setText("");
			}
			}
			catch(Exception e){
				tvDoKho.setText("Please input a number from 1 to 3");
			}
		if(tvSoMau.getText().toString()!="" || tvChieuDai.getText().toString()!=""
				||tvChieuCao.getText().toString()!=""||tvDoKho.getText().toString()!=""){
		return false;
		}
		else {
			return true;
		
		}
}


}
